let getRandomBasic = (function () {
  let today = new Date();
  let seed = today.getTime();
  function rnd() {
    seed = (seed * 9301 + 49297) % 233280;
    return seed / 233280.0;
  }
  return function rand(number) {
    return Math.ceil(rnd() * number);
  };
})();

function isObject(obj) {
  if (obj === undefined || obj === null) {
    return false;
  } else {
    return toString.call(obj) == "[object Object]";
  }
}

function getRandom() {
  if (typeof Uint32Array === "function") {
    let cry = "";
    if (typeof crypto !== "undefined") {
      cry = crypto;
    } else if (typeof msCrypto !== "undefined") {
      cry = msCrypto;
    }
    if (isObject(cry) && cry.getRandomValues) {
      let typedArray = new Uint32Array(1);
      let randomNumber = cry.getRandomValues(typedArray)[0];
      let integerLimit = Math.pow(2, 32);
      return randomNumber / integerLimit;
    }
  }
  return getRandomBasic(10000000000000000000) / 10000000000000000000;
}

export default function getUUID() {
  return (
    "" +
    Date.now() +
    "-" +
    Math.floor(1e7 * getRandom()) +
    "-" +
    getRandom().toString(16).replace(".", "") +
    "-" +
    String(getRandom() * 31242)
      .replace(".", "")
      .slice(0, 8)
  );
}

